﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using Com.CMS263.DAO;
using Com.CMS263.Util;
namespace Com.CMS263.BLL
{
    public class GuestBLL : BaseBLL<Guest>
    {
        public Guest entity = new Guest();
        public override Guest GetModel()
        {
            return entity;
        }
        private GuestDAO gb = new GuestDAO();
        /// <summary>
        /// 检查邮箱
        /// </summary>
        /// <param name="userEmail"></param>
        /// <returns></returns>
        public bool GetLogEmail(string userEmail)
        {
            return gb.GetLogEmail(userEmail);
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="guest"></param>
        /// <returns></returns>
        public bool InsertReg(Guest guest)
        {
            return gb.InsertReg(guest);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        public void Del(int id)
        {
            gb.Delete(id);
        }
        /// <summary>
        /// 用户ID查找
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Guest GetGuestById(int id)
        {
           return gb.GetGuestById(id);
        }
        /// <summary>
        /// 根据用户名进行分页
        /// </summary>
        /// <param name="username"></param>
        /// <param name="pagesize"></param>
        /// <param name="pageindex"></param>
        /// <returns></returns>
        public IList<Guest> GetGuestList(string username,int pagesize,int pageindex)
        {
            if (string.IsNullOrEmpty(username))
            {
                return gb.GetGuestList(pagesize, pageindex);
            }
            else
            {
                return gb.GetGuestList(username, pagesize, pageindex);
            }
        }
        /// <summary>
        /// 根据用户名查找所有总数
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int GetCount(string user)
        {
            return gb.GetCount(user);
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="pageindex"></param>
        /// <returns></returns>
        public IList<Guest> GetGuestList(int pagesize, int pageindex)
        {
           return gb.GetGuestList(pagesize, pageindex);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="guest"></param>
        /// <returns></returns>
        public bool Edit(Guest guest)
        { return gb.Edit(guest); }
        public Guest GetUserIdByUserEmail(string useremail)
        {
            return gb.GetUserIdByUserEmail(useremail);
        }
    //    public Guest Add(Guest guest)
    //    {
    //        if (isExist(guest.userName))
    //        {
    //            return null;
    //        }
    //        else
    //        {
    //            return gb.Add(guest);
                
    //        }
    //    }
    //    public bool isExist(string userName)
    //    {
    //        return gb.isExist(userName);
    //    }
    //    public bool isExistByU(string UserId)
    //    {
    //        return gb.isExistByU(UserId);
    //    }
    //    public bool DeleteGuestByID(int id)
    //    {
           
    //            gb.Delete(id);
    //            return true;
            
    //    }
        /// <summary>
        /// 检测登录，如果成功过则返回Guest，如果失败返回null
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码，没有MD5加密过</param>
        /// <returns>如成功返回Guest，失败返回null</returns>
        public bool Login(string userEmail, string password)
        {

            Guest guest = gb.Login(userEmail, password);
            if (guest != null)
            {
                LoginInfo li = new LoginInfo(guest.UserName, guest.Id);
                LoginCookie.SaveLoginInfo(li);
                return true;
            }
            else
            {
                return false;
            }
        }
    //    /// <summary>
    //    /// 检测登录，如果成功过则返回Guest，如果失败返回null
    //    /// </summary>
    //    /// <param name="userName">用户名</param>
    //    /// <param name="password">密码，没有MD5加密过</param>
    //    /// <returns>如成功返回Guest，失败返回null</returns>
    //    public bool LoginByVip(string userVip, string password)
    //    {

    //        Guest guest = gb.LoginByVip(userVip, password);
    //        if (guest != null)
    //        {
    //            LoginInfo li = new LoginInfo(guest.userName, guest.id);
    //            LoginCookie.SaveLoginInfo(li);
    //            return true;
    //        }
    //        else
    //        {
    //            return false;
    //        }
    //    }
    //    public IList<Guest> GetGuestList(int pageSize,int pageIndex)
    //    {
    //       return  gb.GetGuestList(pageSize,pageIndex);
    //    }
    //    public Guest GetGuestById(int id)
    //    {
    //        return gb.GetGuestById(id);
    //    }
    //    public bool UpdateGuest(Guest guest)
    //    {
    //        return gb.UpdateGuest(guest);
    //    }
    //    public int GetTotalNum()
    //    {
    //        return gb.GetTotalNum();
    //    }
    //    /// <summary>
    //    /// 根据编号查找用户
    //    /// </summary>
    //    /// <param name="userId"></param>
    //    /// <returns></returns>
    //    public Guest GetGuestByUserId(string userId)
    //    {
    //        return gb.GetGuestByUserId(userId);
    //    }
        public IList<Guest> GetAllUser()
        {
            return gb.GetAllUser();
        }
        /// <summary>
        /// 根据email查询实体
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public Guest FindByEmail(string email)
        {
            try
            {
                return gb.FindByEmail(email);
            }
            catch 
            {
                
                return null;
            }
        }
    }

}
